package com.wx.wxpush.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *@ClassName JiNianRi
 *@Description TODO
 *@Author chen
 *@Date 2022/8/22 09:54
 */
public class JiNianRi {
//    /**
//     * 恋爱
//     */
//    static String lianAi = "2022-03-09 10:06:00";
//    /**
//     * 领证
//     */
//    static String linZheng = "2022-03-19";
//    /**
//     * 结婚
//     */
//    static String jieHun = "2022-07-08";
//    /**
//     * 生日
//     */
//    //static String shengRi = "2023-08-22 00:00:00";

    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * 距离date还有多少天
     * @param date
     * @return
     */
    public static String  before(String date) {
        long day = 0;
        try {
            long nd = 1000 * 24 * 60 * 60;
            // 获得两个时间的毫秒时间差异
            long diff = simpleDateFormat.parse(date).getTime() -  System.currentTimeMillis();
            // 计算差多少天
            day = diff / nd;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String newDay = String.valueOf(day).replace("-","");
        return newDay;
    }


    /**
     * 已经过去date多少天
     * @param date
     * @return
     */
    public static String after(String date) {
        long day = 0;
        try {
            long nd = 1000 * 24 * 60 * 60;
            // 获得两个时间的毫秒时间差异
            long diff =  System.currentTimeMillis() - simpleDateFormat.parse(date).getTime();
            // 计算差多少天
            day = diff / nd;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String newDay = String.valueOf(day).replace("-","");
        return newDay;
    }
    /**
     *  计算距离生日还有多少天
     * @param addtime：生日日期
     */
    public static int getBirthDay(String addtime) {
        int days = 0;
        try {
            SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
            String clidate = addtime;
            Calendar cToday = Calendar.getInstance(); // 存今天
            Calendar cBirth = Calendar.getInstance(); // 存生日
            cBirth.setTime(myFormatter.parse(clidate)); // 设置生日
            cBirth.set(Calendar.YEAR, cToday.get(Calendar.YEAR)); // 修改为本年
            if (cBirth.get(Calendar.DAY_OF_YEAR) < cToday.get(Calendar.DAY_OF_YEAR)) {
                // 生日已经过了，要算明年的了
                days = cToday.getActualMaximum(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);
                days += cBirth.get(Calendar.DAY_OF_YEAR);
            } else {
                // 生日还没过
                days = cBirth.get(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return days;
    }

    public static String getJieHun(String data) {
        return before(data);
    }
//
//    public static int getLinZhen() {
//        return before(linZheng);
//    }

    public static String getLianAi(String data) {
        return before(data);
    }

    public static String getShengRi(String data){
        return before(data);
    }

//    public static void main(String[] args) {
//        System.out.println(getShengRi("2022-08-07 10:06:00"));
//    }


}
